﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.MovieRecorder.CUiMRCRecorderSplashWindow
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Markup;
using System.Windows.Media.Animation;
using Tecnomatix.Engineering.Ui.WPF;


namespace DnProcessSimulateCommands.MovieRecorder;

public class CUiMRCRecorderSplashWindow : 
  Window,
  INotifyPropertyChanged,
  ICommand,
  IComponentConnector
{
  private const string MINIMIZE_UI_REG_PROPERTY = "Minimize to Ribbon";
  private bool m_shouldMinimizeToRibbon;
  internal TextBlock m_counter;
  internal CheckBox m_minimizeUi;
  private bool _contentLoaded;

  public Visibility HideMinimizeUIToRibbon { get; private set; }

  public CUiMRCRecorderSplashWindow()
  {
    this.InitializeComponent();
    this.MinimizeRecordingUIToRibbon = true;
    this.HideMinimizeUIToRibbon = Visibility.Visible;
    this.DataContext = (object) this;
  }

  private void StringAnimationUsingKeyFrames_Completed(object sender, EventArgs e)
  {
    this.Close(this.MinimizeRecordingUIToRibbon);
  }

  private void TxWindow_Loaded(object sender, RoutedEventArgs e)
  {
    HwndSource.FromHwnd(new WindowInteropHelper((Window) this).Handle).AddHook(new HwndSourceHook(this.WndProc));
    this.LoadSettingsFromRegistry();
    Storyboard resource = this.FindResource((object) "StartAnimationStoryBoard") as Storyboard;
    Storyboard.SetTarget((DependencyObject) resource, (DependencyObject) this.m_counter);
    resource.Begin();
    this.MouseEnter += new MouseEventHandler(this.CUiMRCRecorderSplashWindow_MouseEnter);
    this.MouseLeave += new MouseEventHandler(this.CUiMRCRecorderSplashWindow_MouseLeave);
  }

  private void LoadSettingsFromRegistry()
  {
    object obj;
    TxWindowSettings.RestoreWindowValue((Window) this, "Minimize to Ribbon", ref obj);
    bool result;
    if (obj == null || !bool.TryParse(obj.ToString(), out result))
      return;
    this.MinimizeRecordingUIToRibbon = result;
  }

  public bool MinimizeRecordingUIToRibbon
  {
    get => this.m_shouldMinimizeToRibbon;
    set
    {
      this.m_shouldMinimizeToRibbon = value;
      this.OnPropertyChanged(nameof (MinimizeRecordingUIToRibbon));
    }
  }

  public ICommand CloseCommand => (ICommand) this;

  private void Close(bool animate)
  {
    if (animate)
      this.CloseWithAnimation();
    else
      this.Close();
  }

  private void CloseWithAnimation()
  {
    this.SizeToContent = SizeToContent.Manual;
    this.ResizeMode = ResizeMode.CanMinimize;
    Storyboard resource = this.FindResource((object) "MinimimizeWindowAnimationStoryBoard") as Storyboard;
    Rectangle applicationRect = CApMRCRecorderUtilities.GetApplicationRect();
    foreach (DoubleAnimation child in resource.Children)
    {
      if (child.Name == "Top")
      {
        child.From = new double?(this.Top);
        child.To = new double?((double) (applicationRect.Top + 100));
      }
      else if (child.Name == "Left")
      {
        child.From = new double?(this.Left);
        child.To = new double?((double) (applicationRect.Right - 200));
      }
      else if (child.Name == "Width")
      {
        child.From = new double?(this.Width);
        child.To = new double?(this.Width / 2.0);
      }
      else if (child.Name == "Height")
      {
        child.From = new double?(this.Height);
        child.To = new double?(this.Height / 2.0);
      }
      else if (child.Name == "Opacity")
      {
        child.From = new double?(this.Opacity);
        child.To = new double?(0.0);
      }
    }
    resource.Completed += (EventHandler) ((sender, e) => this.Close());
    Storyboard.SetTarget((DependencyObject) resource, (DependencyObject) this);
    resource.Begin();
  }

  private void Window_Closed(object sender, EventArgs e)
  {
    TxWindowSettings.StoreWindowValue((Window) this, "Minimize to Ribbon", (object) this.MinimizeRecordingUIToRibbon);
  }

  public event PropertyChangedEventHandler PropertyChanged;

  protected virtual void OnPropertyChanged(string propertyName)
  {
    if (this.PropertyChanged == null)
      return;
    this.PropertyChanged((object) this, new PropertyChangedEventArgs(propertyName));
  }

  private void CUiMRCRecorderSplashWindow_MouseEnter(object sender, MouseEventArgs e)
  {
    Storyboard resource1 = this.FindResource((object) "StartAnimationStoryBoard") as Storyboard;
    if (resource1.GetCurrentState() == ClockState.Active)
      resource1.Pause();
    Storyboard resource2 = this.FindResource((object) "BlinkAnimationStoryBoard") as Storyboard;
    if (Storyboard.GetTarget((DependencyObject) resource2) != null && resource2.GetCurrentState() != ClockState.Stopped)
      return;
    Storyboard.SetTarget((DependencyObject) resource2, (DependencyObject) this.m_counter);
    resource2.Begin();
  }

  private void CUiMRCRecorderSplashWindow_MouseLeave(object sender, MouseEventArgs e)
  {
    Storyboard resource1 = this.FindResource((object) "BlinkAnimationStoryBoard") as Storyboard;
    if (Storyboard.GetTarget((DependencyObject) resource1) != null && resource1.GetCurrentState() == ClockState.Active)
      resource1.Stop();
    Storyboard resource2 = this.FindResource((object) "StartAnimationStoryBoard") as Storyboard;
    if (!resource2.GetIsPaused())
      return;
    resource2.Resume();
  }

  private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
  {
    if (msg == 33)
    {
      handled = true;
      return new IntPtr(3);
    }
    if (msg != 675)
      return IntPtr.Zero;
    this.CUiMRCRecorderSplashWindow_MouseLeave((object) null, (MouseEventArgs) null);
    return IntPtr.Zero;
  }

  public bool CanExecute(object parameter) => true;

  public event EventHandler CanExecuteChanged;

  public void Execute(object parameter) => this.Close();

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/movierecorder/cuimrcrecordersplashwindow.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    switch (connectionId)
    {
      case 1:
        ((FrameworkElement) target).Loaded += new RoutedEventHandler(this.TxWindow_Loaded);
        ((Window) target).Closed += new EventHandler(this.Window_Closed);
        break;
      case 2:
        ((Timeline) target).Completed += new EventHandler(this.StringAnimationUsingKeyFrames_Completed);
        break;
      case 3:
        this.m_counter = (TextBlock) target;
        break;
      case 4:
        this.m_minimizeUi = (CheckBox) target;
        break;
      default:
        this._contentLoaded = true;
        break;
    }
  }
}
